'use client'
import { Console } from '@bgoodman/react-console-component'

const MyConsole = () => {
    const onInit = (): Promise<string> => {
        // do something when the console is initialized.
        const output = new Date().toString()
        // return the console output as a promise.
        return Promise.resolve(output)
    }

    const evalCmd = (cmd: string) => {
        try {
            // do something with the input command.
            const result = eval(cmd).toString()
            // return the result as a promise
            return Promise.resolve(result)
        } catch (err: any) {
            return Promise.resolve(err.toString())
        }
    }

    return (
        <Console
            onEnter={evalCmd}
            onInit={onInit}
            prompt="$"
            height="300px"
            autoScroll
        />
    )
}

export default MyConsole;